package com.example.sharesinfo.fragment.index;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chauthai.swipereveallayout.SwipeRevealLayout;
import com.example.sharesinfo.R;
import com.example.sharesinfo.adapter.CommonAdapter;
import com.example.sharesinfo.adapter.CommonViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ICommunityFragment extends Fragment {
    private RecyclerView mView;
    private SwipeRevealLayout swipeLayout;
    private View frontLayout;
    private View deleteLayout;
    private CommonAdapter<String> mAdapter;
    private List<String> mList = new ArrayList<>();
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_icommunity, null);
        initView(view);
        return view;
    }

    private void initView(View view) {
        mList=createList(20);
        mView = view.findViewById(R.id.recyclerView);
        mView.setLayoutManager(new LinearLayoutManager(getContext()));
        mAdapter = new CommonAdapter<>(mList, new CommonAdapter.OnBindDataListener<String>() {
            @Override
            public void onBindViewHolder(String model, CommonViewHolder viewHolder, int type, final int position) {
                //viewHolder.setText(R.id.text,model);
                swipeLayout =  viewHolder.itemView.findViewById(R.id.swipe_layout);
                frontLayout = viewHolder.itemView.findViewById(R.id.front_layout);
                deleteLayout = viewHolder.itemView.findViewById(R.id.delete_layout);
                deleteLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mList.remove(position);
                        //notifyItemRemoved(getAdapterPosition());
                    }
                });
            }

            @Override
            public int getLayoutId(int type) {
                return R.layout.test_item;
            }
        });
        mView.setAdapter(mAdapter);

    }
    private List<String> createList(int n) {
        List<String> list = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            list.add("View " + i);
        }

        return list;
    }
}
